<?php
namespace app\job;

use app\api\controller\User;
use think\queue\Job;

class CloseDoor{

    public function fire(Job $job, $data)
    {
        if ($job->attempts() > 4) {
            // 通过这个方法可以检查这个任务已经重试了几次了
            $job->delete();
        } else {
            try {
                $doorObj = new User(app());
                $doorObj->operateDoor(0, $data['user_id'], $data['station_id'], $data['dev_id'], $data['car_type'], $data['scene'], $data['car_id']);
                if ($doorObj->isSuccessByDoor) {
                    $job->delete();
                }
            } catch (\Exception $e) {
                echo $e->getMessage();
            }
        }
    }

    public function failed($data)
    {
        // ...任务达到最大重试次数后，失败了
    }

}